﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConsoleApplication1
{

    public partial class mainForm : Form
    {
        private  Dictionary<KeyValuePair<string, string>, double> allPairs;
        private Dictionary<string, string> allDoc;
        int currentPlace;// count the current pair the expert is ranking now

        public mainForm(Dictionary<KeyValuePair<string, string>, double> result,Dictionary<string, string> allDoc)
        {
            this.InitializeComponent();
            this.allPairs = result;
            this.allDoc = allDoc;
            previousButton.Enabled = false;
            endButton.Enabled = false;
            progressBar1.Value = 0;

            currentPlace = 0;
            initText(allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace)); // this is the main function         
        }
        /// <summary>
        /// this function display on screen the pair of the documents and display the rank of the expert
        /// </summary>
        /// <param name="current">the current pair of documents</param>
        public void initText(KeyValuePair<string, string> current)
        {
            firstFile.Text = allDoc[current.Key];  
            secondFile.Text = allDoc[current.Value];
            docName1.Text = current.Key;
            docName2.Text = current.Value;
            int rank = (int)(allPairs[allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace)]);
            switch (rank)
            {
                case -5: radioButtonMinus5.Checked = true; break;
                case -4: radioButtonMinus4.Checked = true; break;
                case -3: radioButtonMinus3.Checked = true; break;
                case -2: radioButtonMinus2.Checked = true; break;
                case -1: radioButtonMinus1.Checked = true; break;
                case 0: radioButton0.Checked = true; break;
                case 1: radioButton1.Checked = true; break;
                case 2: radioButton2.Checked = true; break;
                case 3: radioButton3.Checked = true; break;
                case 4: radioButton4.Checked = true; break;
                case 5: radioButton5.Checked = true; break;
            }

        }


        /// <summary>
        ///In case the expert chose a grade it's save his choise
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void RadioButton_CheckedChanged(object sender, EventArgs e)
        {
            int i = 0;
            RadioButton button = sender as RadioButton;
            switch (button.Name)
            {
                case "radioButtonMinus5": i = -5; break;
                case "radioButtonMinus4": i = -4; break;
                case "radioButtonMinus3": i = -3; break;
                case "radioButtonMinus2": i = -2; break;
                case "radioButtonMinus1": i = -1; break;
                case "radioButton5": i = 5; break;
                case "radioButton4": i = 4; break;
                case "radioButton3": i = 3; break;
                case "radioButton2": i = 2; break;
                case "radioButton1": i = 1; break;
                case "radioButton0": i = 0; break;

            }
            allPairs[allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace)] = i; // insert into the dictionary the grade



        }
        /// <summary>
        /// in case of pressing the next butten, show the new pair
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nextButton_Click(object sender, EventArgs e)
        {
            progressBar1.Maximum = allPairs.Count - 1;
            progressBar1.Step = 1;
            progressBar1.PerformStep();

            currentPlace++;
            if (currentPlace < allPairs.Count)
            {
                initText(allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace));
                previousButton.Enabled = true;
                endButton.Enabled = false;
                
            }
            if (currentPlace == allPairs.Count - 1)
            {
                nextButton.Enabled = false;
                endButton.Enabled = true;
            }
           


        }
        /// <summary>
        /// in case of pressing the previous butten, show the previous pair
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void previousButton_Click(object sender, EventArgs e)
        {
            progressBar1.Step = -1;
            progressBar1.PerformStep();
            currentPlace--;
            if (currentPlace == 0)
            {
                initText(allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace));
                previousButton.Enabled = false;
                nextButton.Enabled = true;
                endButton.Enabled = false;
            }
            else
                initText(allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace));
            nextButton.Enabled = true;
            endButton.Enabled = false;
        }


    

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            docText form = new docText(allDoc[allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace).Key]);
            form.Show();
        }
        /// <summary>
        /// 
        /// open the doc un the right side
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
   
        private void pictureBox4_Click(object sender, EventArgs e)
        {
            docText form2 = new docText(allDoc[allPairs.Keys.ElementAt<KeyValuePair<string, string>>(currentPlace).Value]);
            form2.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }




    }
}
